﻿using MaterialDesignThemes.Wpf;
using project.B12.application.Views.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace project.B12.application.Extensions
{
    public class DialogExtensions
    {
        /// <summary>
        /// 消息提示对话框
        /// </summary>
        /// <param name="title"></param>
        /// <param name="content"></param>
        /// <param name="dialogHostName"></param>
        /// <returns></returns>
        public static async Task<bool?> MessageTip(string? title, string content, string dialogHostName = "Main")
        {
            if (DialogHost.IsDialogOpen(dialogHostName))
            {
                DialogHost.Close(dialogHostName);
            }
            var msgView = new MsgView(false)
            {
                Title = { Text = title },
                Content = { Text = content },
            };
            var dialogResult = (bool?)await DialogHost.Show(msgView, dialogHostName);
            return dialogResult;
        }

        /// <summary>
        /// 等待对话框
        /// </summary>
        /// <param name="title"></param>
        /// <param name="content"></param>
        /// <param name="dialogHostName"></param>
        /// <returns></returns>
        public static MsgView WaitMessageTip(string title, string content, string dialogHostName = "Main")
        {
            if (DialogHost.IsDialogOpen(dialogHostName))
                return null;
            var msgView = new MsgView(true)
            {
                Title = { Text = title },
                Content = { Text = content },
            };
            DialogHost.Show(msgView, dialogHostName);
            return msgView;
        }

        /// <summary>
        /// 确认/取消对话框
        /// </summary>
        /// <param name="title"></param>
        /// <param name="content"></param>
        /// <param name="dialogHostName"></param>
        /// <returns></returns>

        public static async Task<bool> ConfirmMessage(string title, string content, string dialogHostName = "Main")
        {
            if (DialogHost.IsDialogOpen(dialogHostName))
                return false;
            var msgView = new ConfirmMsgView
            {
                Title = { Text = title },
                Content = { Text = content },
                DialogHostName = dialogHostName,
                
            };
            var dialogResult = (bool?)await DialogHost.Show(msgView, dialogHostName);

            if (dialogResult == true)
                return true;
            else
                return false;
        }

        /// <summary>
        /// 确认/取消对话框
        /// </summary>
        /// <param name="title"></param>
        /// <param name="content"></param>
        /// <param name="confirm">确认按钮的文本</param>
        /// <param name="cancel">取消按钮的文本</param>
        /// <param name="dialogHostName"></param>
        /// <returns></returns>
        public static async Task<bool> ConfirmMessage(string? title, string content, string confirm, string cancel, string dialogHostName = "Main")
        {
            if (DialogHost.IsDialogOpen(dialogHostName))
                return false;
            var msgView = new ConfirmMsgView
            {
                Title = { Text = title },
                Content = { Text = content },
                Confirm = { Content = confirm },
                Cancel = { Content = cancel },
                DialogHostName = dialogHostName,
            };
            var dialogResult = (bool?)await DialogHost.Show(msgView, dialogHostName);

            if (dialogResult == true)
                return true;
            else
                return false;
        }

        /// <summary>
        /// View展示
        /// </summary>
        /// <param name="view"></param>
        /// <param name="dialogHostName"></param>
        /// <returns></returns>
        public static async Task<object> Show(object view, string dialogHostName = "Main")
        {
            if (DialogHost.IsDialogOpen(dialogHostName))
                return null;
            var dialogResult = await DialogHost.Show(view, dialogHostName);
            return dialogResult;
        }

        //public static void Close(string dialogHostName = "Root")
        //{
        //    if (!DialogHost.IsDialogOpen(dialogHostName))
        //        return;
        //    DialogHost.Close(dialogHostName);
        //}
    }
}
